import { meberDetailApi, getYE } from './api';
import { Toast } from 'antd-mobile';
import { Route } from 'dva/router';
import { isToken } from '../../utils/judgmentEquipment';


export default {
    namespace: 'my',
    state: {
        detaList:[],
        msg:"",
        YE: "",
    },
    reducers:{
        save(state, { data }) {
            return { ...state, ...data };
        },
        clearState() {
            return {detaList: [], msg: '', YE: ''};
        }
    },
    effects: {
        *DetailEFF({ }, { put, call }) {
            const result = yield call(meberDetailApi);
            const res = yield call(getYE)
            if (result.code == 200) {
                yield put({ type: 'save', data: {detaList:result.ret,msg:result.msg||[], YE: res.ret.availablePredeposit} });
            } else {
                // Toast.fail(result.msg, 1.5,()=>{});
            }
        },
    },
    subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname, query }) => {
                if (pathname == '/my' ) {
                    dispatch({ type: 'DetailEFF' });
                    if(isToken()){
                        dispatch({ type: 'clearState' });
                    }
                }
            });
        },
    },
};
